package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.DesignArtifactRequestDao;
import com.rmt.www.vo.DesignArtifactRequest;
import com.rmt.www.vo.Request;

public class DesignArtifactRequestDaoImpl implements DesignArtifactRequestDao {

	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	public void deleteDesignArtifactRequestById(int id) {
		this.jdbcTemplate.update("update designartifactrequest set status='deleted' where id=?", 
				new Object[]{id}, new int[]{java.sql.Types.INTEGER});
	}

	public DesignArtifactRequest getDesignArtifactRequestById(int id) {
		return (DesignArtifactRequest) this.jdbcTemplate.queryForObject("select * from designartifactrequest where id=? and status != 'deleted'", 
				new Object[]{id}, new DesignArtifactRequestRowMapper());
	}

	@SuppressWarnings("unchecked")
	public List<DesignArtifactRequest> getDesignArtifactRequestByPId(int pid) {
		return this.jdbcTemplate.query("select * from designartifactrequest where pid=? and status != 'deleted'", 
				new Object[]{pid}, new int[]{java.sql.Types.INTEGER}, new DesignArtifactRequestRowMapper());
	}

	public void insertDesignArtifactRequest(DesignArtifactRequest request) {
		jdbcTemplate.update("insert into designartifactrequest(title,architect,consideration,input,function,output,perfrequest,securityrequest,storagerequest,innerinterface,outerinterface,pid,priority,effort,cost,risk,comment,createrid,createdtime,updaterid,updatedtime,version,status,updatedtimes,designartifactid,requesttype)"+
				"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
				new Object[] {
				request.getTitle(),
				request.getArchitect(),
				request.getConsideration(),
				request.getInput(),
				request.getFunction(),
				request.getOutput(),
				request.getPerfrequest(),
				request.getSecurityrequest(),
				request.getStoragerequest(),
				request.getInnerinterface(),
				request.getOuterinterface(),
				request.getPid(),
				request.getPriority(),
				request.getEffort(),
				request.getCost(),
				request.getRisk(),
				request.getComment(),
				request.getCreaterid(),
				request.getCreatedtime(),
				request.getUpdaterid(),
				request.getUpdatedtime(),
				request.getVersion(),
				request.getStatus(),
				request.getUpdatedtimes(),
				request.getDesignartifactid(),
				request.getRequesttype()
		}, 	new int[] {
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.INTEGER,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR
		});
	}

}
